<?php
/*缩略图类*/
//require_once 'Thumbnail.php';
/*Azure storage*/
require_once __DIR__.'/vendor/autoload.php';
use WindowsAzure\Common\ServicesBuilder;
use WindowsAzure\Blob\Models\CreateContainerOptions;
use WindowsAzure\Blob\Models\PublicAccessType;
use WindowsAzure\Common\ServiceException;

class Azure_Storage{
    /*上传默认图片
     * $container article food teacher student
     */
    public function defaultImg($imgType,$path,$rename){
    	ini_set("max_execution_time",6000);
		
       /* if(!in_array($imgType,array('apk','article','avatar','events','html','notice','logo','advertorial','article-source','avatar-stu'))){
            echo '文件类型必须为advertorial,apk,article,avatar,events,html,notice,logo';exit();
        }
		*/		
        if($path){ 
	        $cloudConn = 'DefaultEndpointsProtocol=http;AccountName=yunxiaoche;AccountKey=58+6G6iMA1OLWFygExPxT0W4oB9SoFJhTY+PwxVLQxR2n4gZjDxf6lfbpcHCCjkBsb52ben/dojKlp462e0n9Q==';
	        $constring = ServicesBuilder::getInstance()->createBlobService($cloudConn);//连接对象
            $content = fopen($path, "r");
            $rs = $constring->createBlockBlob($imgType, $rename, $content);
            if($rs){
            	return 'http://cloud.yunxiaoche.com/'.$imgType.'/'.$rename;
                //echo '上传目录为'.$imgType.'的云URL为:http://yunxiaoche.blob.core.windows.net/'.$imgType.'/'.$rename.'.jpg';
            }else{
            	return -1;
                //echo '上传出现异常!';
            }
        }else{
        	return -2;
            //echo '路径不存在';
        }
        
    }

}
